package com.situ.water_Invoice.mapper;

import com.situ.water_Invoice.pojo.FPZB;
import com.situ.water_Invoice.pojo.IvInvoice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@Mapper
public interface IvInvoiceMapper extends BaseMapper<IvInvoice> {

    //多表连接查询
    @Select("select ivin.InvoiceType,ivin.StartNo,ivin.EndNo,ivin.InCounts,voi.OutCounts,iv.Used,iv.Invalid,ar.ArCounts,ivin.InDate,e.EmpNmae from sy_emp e,iv_Invoice iv,iv_Ininvoice ivin,iv_archive ar,iv_outinvoice voi where iv.InID=ivin.id and iv.ArchiveID=ar.id and  iv.OutID=voi.id and e.ID=iv.EmpID")
    public List<FPZB> FPZB();

    //查询IV_Invoice表 inid 为空的第一条数据
    @Select("select * from IV_Invoice where inid is null LIMIT 1")
    public IvInvoice querynull();

    //查询IV_Invoice表 OutID 为空的第一条数据
    @Select("select * from IV_Invoice where OutID is null LIMIT 1")
    public IvInvoice querynullOutID();

    //查询IV_Invoice表 ArchiveID 为空的第一条数据
    @Select("select * from IV_Invoice where ArchiveID is null LIMIT 1")
    public IvInvoice querynullArchiveID();

    //把查询到的id添加到 IV_Invoice 表中 条件为InvoiceNo
    @Update("update IV_Invoice set inid=#{inid}  where InvoiceNo=#{InvoiceNo}")
    public int updateInInvoice(int inid,String InvoiceNo);

    //把查询到的id添加到 IV_Invoice 表中 条件为InvoiceNo
    @Update("update IV_Invoice set OutID=#{OutID}  where InvoiceNo=#{InvoiceNo}")
    public int updateInInvoiceOutID(int OutID,String InvoiceNo);

    //把查询到的id添加到 IV_Invoice 表中 条件为InvoiceNo
    @Update("update IV_Invoice set ArchiveID=#{ArchiveID}  where InvoiceNo=#{InvoiceNo}")
    public int updateInInvoiceArchiveID(int ArchiveID,String InvoiceNo);

    //销账明细报表
    @Select("select PY_Pay.PayNo,PY_Pay.Invoice,IV_Invoice.InvoiceType,PY_Pay.PayDate,PY_Pay.PayMoney,PY_Pay.UseMoney,SY_Emp.EmpNmae,PY_BillDetail.CostTypeCode,PY_BillDetail.Amount,PY_BillDetail.Price from PY_Pay join IV_Invoice on PY_Pay.Invoice = IV_Invoice.InvoiceNo join SY_Emp on SY_Emp.id=PY_Pay.EmpID join PY_BillDetail on PY_BillDetail.UserNo=PY_Pay.UserNo")
    List<Map> XZMXBB();

}
